<!--其他企业-->
<template>
  <div>
    <a-card class="contentFullHeight"  :bodyStyle="{padding : '10px 10px'}">
      <!--筛选、导入导出-->
      <a-card :bordered="true" class="searchBox" :bodyStyle="{padding : '10px 24px'}">
        <a-form layout="inline">
          <!--<a-form-item label="上传时间">-->
          <!--<a-range-picker-->
          <!--:defaultValue="[moment(searchParams.bgTm, dateFormat), moment(searchParams.endTm, dateFormat)]"-->
          <!--:format="dateFormat"-->
          <!--@change="onChange"-->
          <!--&gt;</a-range-picker>-->
          <!--</a-form-item>-->
          <a-form-item label="企业名称">
            <a-input v-model="searchParams.companyName"></a-input>
          </a-form-item>
          <a-form-item>
            <a-button type="primary" icon="search" @click="handleSearch">查询</a-button>
          </a-form-item>
          <a-form-item>
            <!--新增-->
            <a-button type="primary" icon="plus" @click="handleCreate">新增</a-button>
          </a-form-item>

          <a-form-item>
            <a-button type="primary" icon="download" @click="handleDownload" :loading="downloadLoading">导出</a-button>
          </a-form-item>
          <!--导入-->
          <a-form-item>
            <UploadCom :type="6" @handleSearch="handleSearch"></UploadCom>
          </a-form-item>
        </a-form>
      </a-card>

      <!--列表-->
      <a-table :columns="columns" :dataSource="data"
               bordered size="small" rowKey="id"
               :pagination="pagination" :loading="loading"
               @change="getTableData"
      >
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="openStaff(record)" href="javascript:;">员工</a>
            <a-divider type="vertical"/>
            <a @click="handleUpdate(record)" href="javascript:;">编辑</a>
            <a-divider type="vertical"/>
            <a href="javascript:;" @click="showConfirm(record)">删除</a>
          </template>
        </span>
      </a-table>
      <!--新增/编辑弹窗-->
      <punishPopup :mdl="mdl" @handleSearch="handleSearch" :flfgValueList.sync="flfgValueList"></punishPopup>
      <!--员工-->
      <staffPopup :mdl="mdlStaff"></staffPopup>
    </a-card>
  </div>
</template>

<script>
  import moment from 'moment';
  import punishPopup from './punishPopup'
  import staffPopup from './staffPopup'
  import {queryForOther,companyInfoBasedelete,exportListForOther} from '@/api/business'
  import {downloadFile} from '@/utils/util';
  import UploadCom from '@/components/uploadCom';
  export default {
    components: {
      punishPopup,
      staffPopup,
      UploadCom
    },
    data() {
      return {

        /*   -------搜索框--------*/
        searchParams: {
          companyName:""
        },

        /*   -------分页--------*/
        pagination: this.$defaultSettings.pagination ,

        /*   -------弹窗--------*/
        mdlStaff: {
          visible: false,
          id: ''
        },
        mdl: {
          dialogStatus: '',
          dialogTitleMap: {
            update: '编辑',
            create: '添加'
          },
          visible: false,
          title: '',
          formData: {
            address: "",
            certNo: "",
            companyName: "",
            companyType: 1,
            createTime: "",
            dealTime: "",
            del: 0,
            id: '',
            personName: "",
            pulishNo: "",
            pulishTime: ""
          },
          labelCol: {
            xs: {
              span: 24
            }
            ,
            sm: {
              span: 5
            }
          }
          ,
          wrapperCol: {
            xs: {
              span: 24
            }
            ,
            sm: {
              span: 16
            }
          },
          formItemLayoutWithOutLabel: {
            wrapperCol: {
              xs: { span: 24, offset: 0 },
              sm: { span: 20, offset: 4 },
            },
          },
        },


        /*   -------表格--------*/
        loading: false,
        columns:[
          {
            title: '企业名称',
            dataIndex: 'companyName'
          },
          {
            title: '处罚日期',
            dataIndex: 'pulishTime',
          },
          {
            title: '录入日期',
            dataIndex: 'createTime',
          },
          {
            title: '处理期限',
            dataIndex: 'dealTime',
          },
          {
            title: '处罚文书号',
            dataIndex: 'pulishNo',
          },
          {
            title: '地址',
            dataIndex: 'address',
          },
          {
            title: '法人',
            dataIndex: 'personName',
          },
//          {
//            title: '已学课时',
//            dataIndex: 'period'
//          },
          {
            title: '已得积分',
            dataIndex: 'integral'
          },
          {
            title: '证书编号',
            dataIndex: 'certNo'
          },
          {
            title: '操作',
            dataIndex: 'action',
            width: '150px',
            scopedSlots: {customRender: 'action'}
          }
        ],
        data:[],

        // 下载
        downloadLoading: false,
//        法律法规
        flfgValueList: []
      }
    },
    inject: ['upShow'],
    filters: {

    },
    created() {
      this.getTableData(this.pagination)
    },
    computed: {

    },
    methods: {
      getTableData(pagination) {
        if(pagination!=undefined && pagination!='' && pagination!=null) {
          this.pagination = pagination
        }
        this.loading = true
        const parameter = {
          _search: true,//是否分页查询
          pageSize: this.pagination.pageSize || 10,
          pageNumber: this.pagination.current || 1,
          data: {
            address: "",
            certNo: "",
            companyName: this.searchParams.companyName,
            companyType: 1,
            createTime: "",
            dealTime: "",
            del: 0,
            id: '',
            personName: "",
            pulishNo: "",
            pulishTime: ""
          },
          bgTm:'',
          endTm:'',
        }
        queryForOther(parameter).then(res => {
          this.loading = false
          this.pagination.total = res.data.total
          res.data.records.forEach(e=> {
            e.pulishTime = e.pulishTime.split(' ')[0]
            e.dealTime = e.dealTime.split(' ')[0]
          })
          this.data = res.data.records
        }).catch(err => {
          this.loading = false
        })
      },
//      查询
      handleSearch() {
        this.pagination.current = 1
        this.getTableData()
      },
//      清空
      setDefaults() {
        this.mdl.formData = {
          address: "",
          certNo: "",
          companyName: "",
          companyType: 1,
          createTime: "",
          dealTime: "",
          del: 0,
          id: '',
          personName: "",
          pulishNo: "",
          pulishTime: ""
        }
        this.flfgValueList = []
      },
      //添加行
      handleCreate() {
        this.setDefaults()
        this.mdl.dialogStatus = 'create'
        this.mdl.visible = true
      },
//      打开员工弹窗
      openStaff(row) {
        this.mdlStaff.visible = true
        this.mdlStaff.id = row.id
      },
      //编辑当前行
      handleUpdate(row) {
        this.mdl.formData = Object.assign({}, row) // copy obj
        this.mdl.dialogStatus = 'update'
//        所绑定的法律法规回显
        this.flfgValueList= []
        if(this.mdl.formData.docId != '' && this.mdl.formData.docId != null) {
          if(this.mdl.formData.docId.indexOf(',')==-1) {
            this.flfgValueList.push(this.mdl.formData.docId)
          }else {
            this.flfgValueList = this.mdl.formData.docId.split(',')
          }
        }else {
          this.flfgValueList = []
        }
        this.mdl.visible = true
      },
      //删除
      handleDelete(row) {
        companyInfoBasedelete(row.id).then(res => {
          if(res.code === 200) {
            this.upShow(1,res.msg || '删除成功')
            this.handleSearch()
          } else {
            this.upShow(2,res.msg)
          }
        }).catch(err => {
          this.upShow(2)
        })
      },
      showConfirm(val) {
        var that = this
        this.$confirm({
          title: '删除企业记录?',
          content: '确定删除'+val.companyName +'记录?',
          onOk() {
            that.handleDelete(val)
          },
          onCancel() {},
        });
      },
      //下载
      handleDownload() {
        this.downloadLoading = true
        let param  ={
          "_search": false,
          "bgTm": "",
          "data": {
            address: "",
            certNo: "",
            companyName: this.searchParams.companyName,
            companyType: 0,
            createTime: "",
            dealTime: "",
            del: 0,
            id: '',
            personName: "",
            pulishNo: "",
            pulishTime: ""
          },
          pageSize: '',
          pageNumber: '',
          endTm:'',
        }
        exportListForOther(param).then(res=> {
          downloadFile(res,"警示教育企业","xlsx")
          this.downloadLoading = false
        })
      }
    }
  }
</script>

<style scoped>

</style>